<?php
 function microtime_float()
{
		list($usec, $sec) = explode(" ", microtime());
		return ((float)$usec + (float)$sec);
}
function send_get($url) 
{  
    $context = array ();  
    $data = array ();
	$context ['http'] = array (   
		'timeout' => 20,    
		'method' => 'GET',    
		'header' => 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh_CN) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/18.0 BIDUBrowser/2.6 Safari/534.7'   
	 );     
	$getstr="";
	$time_start =microtime_float();
	@file_get_contents ($url, false, stream_context_create ( $context ) ); 
	$time_end =microtime_float();
	$time = $time_end - $time_start;
	$time = ceil($time * 1000);
	foreach($http_response_header as $key=>$value){
		 $getstr.=$value;	
	}
	$getstrstr = $http_response_header[0];
	
	if(http_response_header){
		if(strstr($getstrstr,"HTTP/")){
			if(strstr($getstrstr,"200 OK")){				
				echo '{"code":"1","times":"'.$time.'","httpcode":"200"}';
			} else if(strstr($getstrstr,"302")){
				echo '{"code":"1","times":"'.$time.'","httpcode":"302"}';
					
			} else if(strstr($getstrstr,"301")){
				echo '{"code":"1","times":"'.$time.'","httpcode":"301"}';
			}else{
				$warningcode = substr($getstrstr,8);
				echo '{"code":"0","times":"'.$time.'","httpcode":"'.$warningcode.'"}';
			}
		}else{
				if(strstr($getstr,"200 OK")){				
					echo '{"code":"1","times":"'.$time.'","httpcode":"200"}';
				} else if(strstr($getstr,"302")){
					echo '{"code":"1","times":"'.$time.'","httpcode":"302"}';
						
				} else if(strstr($getstr,"301")){
					echo '{"code":"1","times":"'.$time.'","httpcode":"301"}';
				}else{
					echo '{"code":"0","times":"'.$time.'","httpcode":"0"}';
				}
			}
	}else{
			echo '{"code":"0","times":"'.$time.'","httpcode":"0"}';
		}
	
	// if(strstr($getstr,"200 OK")){
		// echo '{"code":"1","times":"'.$time.'"}';
	// } else if(strstr($getstr,"302")){
		// echo '{"code":"1","times":"'.$time.'"}';
			
	// } else if(strstr($getstr,"301")){
		// echo '{"code":"1","times":"'.$time.'"}';
	// }else{
		// echo '{"code":"0","times":"'.$time.'"}';
	// }
}
$host=$_GET["host"];
send_get($host);
 
?>